new Vue({
    el:"#app",
    data(){
        var password = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('不能为空'));
            }  else {
                callback();
            }
        };
        return {

            loginFrom:{
                account:'',
                password:''
            },
            // password:{
            //     password:[{ pattern: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,18}$/, message: '密码中必须有字母加数字，不得小于6位',trigger: 'blur' },
            //         {validator: password, trigger: 'blur' }
            //     ]
            // }
        }
    },
    methods:{
        login(){
            var that = this;
            this.$refs.loginFrom.validate((valid) =>{
                if (valid) {
                    $.ajax({
                        url: '/login.do',
                        data: that.loginFrom,
                        dataType: 'json',
                        type: 'post',
                        success: function(data) {
                            if (data.code == 200){
                                window.location.href = "/user.html"
                            }
                            if (data.code == 500){
                                that.$message.error(data.msg);
                            }
                        },
                        error:function(){
                            that.$message.error("网络问题！！！！！！！");
                        }
                    })
                }else {
                    // this.$message.error("用户名密码不能为空!!!")
                    return false;
                }
            })

        },
        toRegister(){
            window.location.href = "/register.html"
        }
    }
})